public class Test {
    public static void main(String[] args) {
        int[] nums={1,3,4,5,5,6,7,7,8};
        int len=removeDuplicates(nums);
        for(int i=0;i<len;i++){
            System.out.printf(nums[i]+",");
        }
        System.out.println();
        int[] numsProfit={7,3,4,1,5,6,7,7,8};
        System.out.println(getMaxProfit(numsProfit));


        rotateArray(numsProfit,1);
    }

    private static int removeDuplicates(int[] nums) {
        if(nums.length==0){
            return 0;
        }
        int i=0;
        for(int j=1;j<nums.length;j++){
            if(nums[i]!=nums[j]){
//                i++;
                nums[++i]=nums[j];
            }
        }
        return i+1;
    }


    //股票最佳买入时机
    public static int getMaxProfit(int []arr){
        if (arr.length==0) {
            return 0;
        }
        int profit=0;
        for(int i=1;i<arr.length;i++){
            if(arr[i]>arr[i-1]){
                profit=profit+(arr[i]-arr[i-1]);
            }
        }
        return profit;
    }

    //数组旋转
    public static void rotateArray(int[] nums, int k) {
        int temp,previous;
        for(int i=0;i<k;i++){
            previous=nums[nums.length-1];
            for(int j=0;j<nums.length;j++){
                temp=nums[j];
                nums[j]=previous;
                previous=temp;
            }

        }
        for(int j=0;j<nums.length;j++){
            System.out.print(nums[j]+",");
        }
    }



}
